<?php

namespace GamesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @author  coffey  <coffey@nligo.com>
 * AdminUser
 *
 * 管理员用户
 * @ORM\Table(name="admin_user")
 * @ORM\Entity(repositoryClass="GamesBundle\Repository\AdminUserRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class AdminUser implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer",options={"comment":"管理员自增ID"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", unique=true,name="username",options={"comment":"管理员用户名"})
     */
    private $username = '';

    /**
     * @ORM\Column(type="string",name="nickname",options={"comment":"管理员昵称"})
     */
    private $nickname = '';

    /**
     * @ORM\Column(type="string",name="password",options={"comment":"管理员密码"})
     */
    private $password;

    /**
     * @ORM\Column(type="string", unique=true,name="phone",options={"comment":"用户手机号"})
     */
    private $phone = '';

    /**
     * @ORM\Column(type="json_array",name="roles",options={"comment":"管理员角色"})
     */
    private $roles = array();

    /**
     * @var integer
     * @ORM\Column(type="integer",name="enabled",options={"comment":"管理员状态 0为启用 1为禁用"})
     */
    private $enabled = '0';

    /**
     * @var integer
     * @ORM\Column(type="integer",name="create_time",options={"comment":"创建时间"})
     */
    public $createTime = "";


    /**
     * @ORM\PrePersist
     */
    public function PrePersist()
    {
        $this->setCreateTime(time());
    }

    public function getId()
    {
        return $this->id;
    }

    /**
     * {@inheritdoc}
     */
    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * {@inheritdoc}
     */
    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * Returns the roles or permissions granted to the user for security.
     */
    public function getRoles()
    {
        $roles = $this->roles;
        // guarantees that a user always has at least one role for security
        if (empty($roles)) {
            $roles[] = 'ROLE_ADMIN';
        }
        return array_unique($roles);
    }

    /**
     * @param String
     */
    public function setRole($role)
    {
        $this->roles[] = $role;
    }

    /**
     * @param array
     */
    public function setRoles(array $roles)
    {
        $this->roles = (array)$roles;
    }

    /**
     * Returns the salt that was originally used to encode the password.
     */
    public function getSalt()
    {
        // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
        // we're using bcrypt in security.yml to encode the password, so
        // the salt value is built-in and you don't have to generate one
        return;
    }

    /**
     * Removes sensitive data from the user.
     */
    public function eraseCredentials()
    {
        // if you had a plainPassword property, you'd nullify it here
        // $this->plainPassword = null;
    }

    /**
     * Set enabled
     *
     * @param integer $enabled
     *
     * @return User
     */
    public function setEnabled($enabled)
    {
        $this->enabled = $enabled;
        return $this;
    }

    /**
     * Get enabled
     *
     * @return integer
     */
    public function getEnabled()
    {
        return $this->enabled;
    }

    /**
     * Set nickname
     *
     * @param string $nickname
     *
     * @return User
     */
    public function setNickname($nickname)
    {
        $this->nickname = $nickname;
        return $this;
    }

    /**
     * Get nickname
     *
     * @return string
     */
    public function getNickname()
    {
        return $this->nickname;
    }

    /**
     * Set createtime
     *
     * @param integer $createtime
     *
     * @return Message
     */
    public function setCreateTime($createtime)
    {
        $this->createTime = $createtime;
        return $this;
    }

    /**
     * Get createtime
     *
     * @return integer
     */
    public function getCreateTime()
    {
        return $this->createTime;
    }

    /**
     * Set phone
     *
     * @param string $phone
     *
     * @return AdminUser
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }
}
